﻿#include "texture_wrapper.h"
#include "ui_texture_wrapper.h"
#pragma execution_character_set("utf-8")

texture_wrapper::texture_wrapper(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::texture_wrapper)
{
    ui->setupUi(this);

    ui->tableWidget->setColumnCount(2);
    QStringList header;
    header<<"number"<<"described";
    ui->tableWidget->setHorizontalHeaderLabels(header);
    ui->tableWidget->verticalHeader()->setVisible(false);

    ui->tableWidget->setColumnWidth(0,ui->tableWidget->width()/3);
    ui->tableWidget->setColumnWidth(1,ui->tableWidget->width()/3*2);

    void(QSpinBox::*spSignal1)(int) = &QSpinBox::valueChanged;
    connect(ui->spinBox,spSignal1,ui->horizontalSlider,&QSlider::setValue);
    connect(ui->horizontalSlider, &QSlider::valueChanged, ui->spinBox, &QSpinBox::setValue);

    void(QSpinBox::*spSignal2)(int) = &QSpinBox::valueChanged;
    connect(ui->spinBox_2,spSignal2,ui->horizontalSlider_2,&QSlider::setValue);
    connect(ui->horizontalSlider_2, &QSlider::valueChanged, ui->spinBox_2, &QSpinBox::setValue);
}

texture_wrapper::~texture_wrapper()
{
    delete ui;
}

void texture_wrapper::receiver(patternstore *all_store)
{
    t_all_store = all_store;
    on_tableWidget_itemSelectionChanged(); //显示图案库
}


void texture_wrapper::on_tableWidget_itemSelectionChanged()
{
    QTableWidgetItem *item[2];
    int i,nCount;
    //qDebug()<<"t_all_store.picture_count:"<<t_all_store->picture_count;
    for(i=0; i<t_all_store->picture_count; i++)
    {
        nCount = ui->tableWidget->rowCount();
        ui->tableWidget->insertRow(nCount);

        item[0] = new QTableWidgetItem(QString("%1").arg(i+1));
        item[1] = new QTableWidgetItem(t_all_store->p_picture[i].p_text);
        ui->tableWidget->setItem(i, 0, item[0]);
        ui->tableWidget->setItem(i, 1, item[1]);
    }
}

//刷新按钮
void texture_wrapper::on_pushButton_2_clicked()
{
    this->on_tableWidget_itemSelectionChanged();
}




void texture_wrapper::on_tableWidget_itemClicked(QTableWidgetItem *item)
{
    //qDebug()<<item->row<<item->column()<<"图案库";
    //QString strText = ui->tableWidget_1->item(row, column)->text();
    //qDebug()<<strText;
    cur_sel = item->row();    //选择当前文案库
    qDebug()<<item->row()<<"图案库";
    //ui->spinBox->setValue(cur_sel);
    //ui->spinBox->setValue(all_store.p_picture[cur_sel].radius);
    //ui->spinBox_1->setValue(all_store.p_picture[cur_sel].angle);

}

void texture_wrapper::on_pushButton_clicked()
{
    t_all_store->sel_picture.push_back(cur_sel);   //保存选中的图案编号，可删除
    t_all_store->p_picture[cur_sel].radius = ui->spinBox->value();
    t_all_store->p_picture[cur_sel].angle = ui->spinBox_2->value();

    //t_all_store->p_layer.sel_picture
    int angle = ui->spinBox->value();
    int radius = ui->spinBox_2->value();
    qreal scale = ui->SpinBox_scale->value();
    pixpicture temp_pix = {cur_sel, radius, angle, scale};
    t_all_store->p_layer.push_back(temp_pix);
    qDebug()<<"test1";
    close();
}
